angular.module('MyApp')
    .controller('UsersCtrl', ['$scope', 'users', 'user', function ($scope, users, user) {
        $scope.genderList = users.getGenderList();
        $scope.step = 1;

        $scope.user = user;

        loadUsers();

        function loadUsers() {
            var http = users.all();

            http.then(function(response) {
                $scope.users = response.data.result;
            })
        }


        $scope.nextStep = function () {
            if ($scope.user.validate()) {
                $scope.step = 2;
            }
        }
        $scope.addNew = function () {
            users.add($scope.user).then(function() {
                loadUsers();
           });

        }

    }]);